﻿using System;
using System.Data;
using Core.Library;
using DataObject;
using DataObject.Members;
using DataObject.Ref;

namespace Event.Controls.Common
{
    public partial class MembersInSlide : System.Web.UI.UserControl
    {
        #region variables, constants, properties
        private const int width = 70;
        private const int height = 70;
        private const int topInSlide = 3;
        private const string LI_FORMAT = @"<li {3} ><a href=""{1}"">{2}{0} </a></li>";
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            var dt = MembersCache.Members_InSlide(topInSlide, RefCache.Ref_GetCurrentRound());
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    var r = dt.Rows[i];
                    var avatar = Utils.Photo.BuildPhoto(
                        source: r[Constants.Table_Members.Member_Avatar].ToString(),
                        title: r[Constants.Table_Members.Member_FullName].ToString(),
                        width: width,
                        height: height);
                    var cls = string.Empty;
                    if (i == 2) cls = "class=\"last\"";

                    this.ltrList.Text += string.Format(LI_FORMAT, r[Constants.Table_Members.Member_FullName], r[Constants.Table_Members.Url], avatar, cls);
                }
                phMembersInSlide.Visible = true;
            }
        }
    }
}